package org.nobody.mallb2c.mallorder.web;

import com.alipay.api.AlipayApiException;
import org.nobody.mallb2c.mallorder.config.AlipayTemplate;
import org.nobody.mallb2c.mallorder.service.OrderService;
import org.nobody.mallb2c.mallorder.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 3489309323@qq.com
 * @create 2020-09-27-14:08
 */
@Controller
public class PayWebController {
  @Autowired
  AlipayTemplate alipayTemplate;

  @Autowired
  OrderService orderService;

  /**
   * 1、将支付页让浏览器展示
   * 2、支付成功以后,我们要跳到用户的订单列表页
   * @param orderSn
   * @return
   * @throws AlipayApiException
   */
  @ResponseBody
  @GetMapping(value = "/payOrder",produces = "text/html")
  public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
//    PayVo payVo = new PayVo();
//    payVo.setBody(); //订单的备注
//    payVo.setOut_trade_no(); //订单号
//    payVo.setSubject(); //订单的主题
//    payVo.setTotal_amount(); //订单的金额

    PayVo payVo = orderService.getOrderPay(orderSn);

    String pay = alipayTemplate.pay(payVo);
    System.out.println(pay); //此时支付宝发回的是一个会立即提交的表单, 然后会跳转到
    return pay;
  }
}
